package com.zxmr.util;


public class ResourceManager {

	static String file = "ApplicationResource.properties";

	static ResourceManager instance;
	ResourceLoader loader;
	public static ResourceManager getInstance()
	{
		if(instance == null)instance = new ResourceManager();
		return instance;
	}
	private ResourceManager()
	{
		try
		{
			loader = new ResourceLoader(file);
			loader.init();
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
	public static String getFile() {
		return file;
	}

	public static void setFile(String file) {
		ResourceManager.file = file;
	}
	public String getMessage(String key, String ...args)
	{
		String resource = loader.get(key);
		if(resource == null)return "";
		int number = 1;
		for(String arg : args)
		{
			if(arg == null)arg = "";
			resource = resource.replaceAll("\\{"+number+"\\}", arg);
			number++;
		}
		return resource;
	}
	
}
